#define GL_GLEXT_PROTOTYPES
#define EGL_EGLEXT_PROTOTYPES

#define _GNU_SOURCE

#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
#include <GLES2/gl2.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include "eglut.h"

static void
gears_idle(void)
{

}

/** 
 * Handles a new window size or exposure.
 * 
 * @param width the window width
 * @param height the window height
 */
static void
gears_reshape(int width, int height)
{
   /* Set the viewport */
   glViewport(0, 0, (GLint) width, (GLint) height);
}


/** 
 * Draws the gears.
 */
static void
gears_draw(void)
{
	glClearColor(0.0, 0.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}

/** 
 * Handles special eglut events.
 * 
 * @param special the event to handle.
 */
static void
gears_special(int special)
{
   switch (special) {
      case EGLUT_KEY_LEFT:
         printf("EGLUT_KEY_LEFT");
         break;
      case EGLUT_KEY_RIGHT:
         printf("EGLUT_KEY_RIGHT");
         break;
      case EGLUT_KEY_UP:
         printf("EGLUT_KEY_UP");
         break;
      case EGLUT_KEY_DOWN:
         printf("EGLUT_KEY_DOWN);
         break;
   }
}

int
main(int argc, char *argv[])
{
   /* Initialize the window */
   eglutInitWindowSize(300, 300);
   eglutInitAPIMask(EGLUT_OPENGL_ES2_BIT);
   eglutInit(argc, argv);

   eglutCreateWindow("es2gears");

   /* Set up eglut callback functions */
   eglutIdleFunc(gears_idle);
   eglutReshapeFunc(gears_reshape);
   eglutDisplayFunc(gears_draw);
   eglutSpecialFunc(gears_special);

   /* Initialize the gears */
   gears_init();

   eglutMainLoop();

   return 0;
}
